package com.zfjt.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.ClientmessageBean;
import com.zfjt.entity.OrderBean;
import com.zfjt.entity.ReturnBean;
import com.zfjt.packnum.PackNum00026;
import com.zfjt.service.ClientmessageBeanService;

/**
 * 审核订单
 * @author xk
 * @version 1.0
 * @date 2017年4月08日
 */
@Controller
public class CheckOrderController {

	private ReturnBean mReturn;
	
	@Autowired
	private ClientmessageBeanService mClientMessage;
	
	private Map<String, String> fhdata; 
	
	private List<OrderBean> mData;
	
	@RequestMapping(value="00026")
	@ResponseBody
	public ReturnBean AddBrabch(HttpSession hseesion){
		mData = new ArrayList<>();
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		PackNum00026 num00026 = JSON.parseObject(data,PackNum00026.class); 	
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {//校验码错误
			mReturn.setCode("001");
			mReturn.setPortnum("00026");
			fhdata.put("error", "TOKEN_ERROR");
			String fh = JSON.toJSONString(fhdata);
			mReturn.setData(fh);
		}else{
			ClientmessageBean cx = mClientMessage.selectByPrimaryKey((short) Integer.parseInt(num00026.getId()));
			if (num00026.getType().equals("1")) {//通过审核，把订单状态设置为已通过，把金额装到Money字段中
				cx.setType("3");
				cx.setMoney(num00026.getMoney());
			}else if (num00026.getType().equals("2")) {//未通过审核，把订单状态设置为未通过，把拒绝理由装到Money字段中
				cx.setType("5");
				cx.setMoney(num00026.getMoney());
			}
			mClientMessage.updateByPrimaryKeySelective(cx);
			mReturn.setCode("000");
			mReturn.setPortnum("00026");
			mReturn.setData("chenggong");
		}
		return mReturn;
	}
}
